#include "Runnable_PCH.h"
#include "Defs.h"

/*--------------------------------------------------------------------------*/

std::string GetFileName(const std::string& path)
{
	std::string filefullname = ::GetFileFullname(path);
	uint pathlength = filefullname.length();

	for (uint i = 0; i < pathlength; ++i)
	{
		if (filefullname[i] == '.')
		{
			return filefullname.substr(0, i);
		}
	}

	return filefullname;
}

/*--------------------------------------------------------------------------*/

std::string GetFileExt(const std::string& path)
{
	std::string filefullname = ::GetFileFullname(path);
	uint pathlength = filefullname.length();

	for (uint i = 0; i < pathlength; ++i)
	{
		if (filefullname[i] == '.')
		{
			return filefullname.substr(i, filefullname.length());
		}
	}

	return "";
}

/*--------------------------------------------------------------------------*/

std::string GetFileFullname(const std::string& path)
{
	std::string temp;
	uint pathlength = path.length();

	for (uint i = 0; i < pathlength; ++i)
	{
		if (path[i] != '/' && path[i] != '\\')
		{
			temp += path[i];
		}
		else
		{
			temp = "";
		}
	}

	return temp;
}

/*--------------------------------------------------------------------------*/

std::string GetFilePath(const std::string& path)
{
	std::string toreturn, temp;
	uint pathlength = path.length();

	for (uint i = 0; i < pathlength; ++i)
	{
		if (path[i] != '/')
		{
			temp += path[i];
		}
		else
		{
			toreturn += temp + "/";
			temp = "";
		}
	}

	return toreturn;
}

/*--------------------------------------------------------------------------*/

std::ostream& operator<<(std::ostream& out, const glm::vec2& vec)
{
	out << "{" << vec.x << " " << vec.y << "}";
	return out;
}

/*--------------------------------------------------------------------------*/

std::ostream& operator<<(std::ostream& out, const glm::vec3& vec)
{
	out << "{" << vec.x << " " << vec.y << " " << vec.z << "}";
	return out;
}

/*--------------------------------------------------------------------------*/

std::ostream& operator<<(std::ostream& out, const glm::vec4& vec)
{
	out << "{" << vec.x << " " << vec.y << " " << vec.z << " " << vec.w << "}";
	return out;
}

/*--------------------------------------------------------------------------*/

std::ostream& operator<<(std::ostream& out, const glm::ivec2& vec)
{
	out << "{" << vec.x << " " << vec.y << "}";
	return out;
}

/*--------------------------------------------------------------------------*/

std::ostream& operator<<(std::ostream& out, const glm::ivec3& vec)
{
	out << "{" << vec.x << " " << vec.y << " " << vec.z << "}";
	return out;
}

/*--------------------------------------------------------------------------*/

std::ostream& operator<<(std::ostream& out, const glm::ivec4& vec)
{
	out << "{" << vec.x << " " << vec.y << " " << vec.z << " " << vec.w << "}";
	return out;
}

/*--------------------------------------------------------------------------*/

std::ostream& operator<<(std::ostream& out, const glm::mat4& mat)
{
	out << "#c{";

	for (uint x = 0; x < 4; ++x)
	{
		for (uint y = 0; y < 4; ++y)
		{
			out << " " << mat[y][x]; //human friendly
		}

		if (x != 3)
		{
			out << "; ";
		}
		else
		{
			out << " }";
		}
	}

	return out;
}

/*--------------------------------------------------------------------------*/

std::string GetFileContent( const std::string& path )
{
	std::ifstream file(path.c_str());
	std::stringstream buffer;
	buffer << file.rdbuf();

	return buffer.str();
}

/*--------------------------------------------------------------------------*/